package ord_list;
import java.util.Iterator;
import java.util.ListIterator;
import java.util.LinkedList;

public class OrderedLinkedList<E extends Comparable<E>> implements OrderedList<E> {
	private LinkedList<E> l;
	
	

	public OrderedLinkedList() {
		this.l = new LinkedList<E>();
	}
	
	public OrderedLinkedList(Iterator<E> it) {
		this();
		
		while (it.hasNext()) 
			add(it.next());
	}
	

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((l == null) ? 0 : l.hashCode());
		return result;
	}

	//must check
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		@SuppressWarnings("unchecked")
		OrderedLinkedList<E> other = (OrderedLinkedList<E>) obj;
		if (l == null) {
			if (other.l != null)
				return false;
		} else if (!l.equals(other.l))
			return false;
		return true;
	}

	@Override
	public boolean contains(E e) {
		return ListUtil.contains(this, e);
	}

	@Override
	public E get(int index) {
		return l.get(index);
	}

	@Override
	public Iterator<E> iterator() {
		return l.iterator();
	}

	@Override
	public ListIterator<E> listIterator() {
		return l.listIterator();
	}

	@Override
	public boolean remove(E e) {
		return ListUtil.remove(this, e);
	}

	@Override
	public int size() {
		return l.size();
	}

	@Override
	public int compareTo(OrderedList<E> o) {
		return ListUtil.compareTo(this, o);
	}

	@Override
	public boolean add(E e) {
		return ListUtil.add(this, e);
	}

	@Override
	public boolean addAll(Iterable<E> o1) {
		return ListUtil.addAll(o1, this);
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return l.toString();
	}
	
	

}